#include "StdAfx.h"
#include "DrawLaplaceC.h"


CDrawLaplaceC::CDrawLaplaceC(void)
{
}


CDrawLaplaceC::~CDrawLaplaceC(void)
{
}
BEGIN_MESSAGE_MAP(CDrawLaplaceC, CDrawOpenCV)
	ON_WM_PAINT()
END_MESSAGE_MAP()


void CDrawLaplaceC::DealwithFrame()
{
	// TODO: Add your command handler code here
	if(m_pFrame == NULL)
	{			
		return ;
	}
	if(m_pShow != NULL)
	{
		cvReleaseImage(&m_pShow);
	} 
 
	m_pShow = (IplImage *)cvClone(m_pFrame);

	IplImage* pImgLaplace = NULL;
	IplImage* pImgPlanes[3] = {0,0,0};
	int   i;
 
	pImgLaplace= cvCreateImage(cvGetSize(m_pShow),
						IPL_DEPTH_16S,1);

	if (m_pShow->nChannels==1) {
		cvLaplace(m_pShow,pImgLaplace,3);
		cvConvertScaleAbs(pImgLaplace,m_pShow, 1, 0 );
	}
	else {
		for (i=0;i<3;i++) {
			pImgPlanes[i] = cvCreateImage(cvGetSize(m_pShow),
						IPL_DEPTH_8U,1);
		}
 
		cvCvtPixToPlane(m_pShow,pImgPlanes[0],
				pImgPlanes[1],pImgPlanes[2],0);

		for (i=0;i<3;i++) {
			cvLaplace(pImgPlanes[i],pImgLaplace,3);
			cvConvertScaleAbs(pImgLaplace,pImgPlanes[i], 1, 0 );
		}

		cvCvtPlaneToPix(pImgPlanes[0],pImgPlanes[1],
				pImgPlanes[2],0,m_pShow);

		for (i=0;i<3;i++) {
			cvReleaseImage(&pImgPlanes[i]);
		}
	}
	cvReleaseImage(&pImgLaplace);
}
